$(function () {
    if (window.parent === window.self) {
        max_width = window.document.documentElement.clientWidth;
        max_height = window.document.documentElement.clientHeight;
    } else {
        var panel = $(".tabs-panels", window.parent.document);

        max_width = panel.width;
        max_height = panel.height;
    }

    $('#listGrid').datagrid({
        fit: true,
        toolbar: '#toolbar',
        title: '客户列表',
        iconCls: 'icon icon-chart_organisation',
        rownumbers: true,
        singleSelect: true,
        pagination: true,

        url: '/sys/customer/list',
        queryParams: {
            _token: $('meta[name="csrf-token"]').attr('content'),
            curr_menu_id: $('meta[name="curr_menu_id"]').attr('content')
        },
        columns: [[
            {title: 'id', field: 'id', hidden: true},
            {title: '客户名称', field: 'name'},
            {title: '描述', field: 'description'},
            {title: '贸易类型', field: 'business_type'},
            {title: '纳税人识别号', field: 'taxid'},
            {title: '开票地址', field: 'adds'},
            {title: '电话', field: 'phone'},
            {title: '开户银行', field: 'bank'},
            {title: '开户银行账号', field: 'bankAcc'},
            {title: '省市县信息', field: 'address_detail'},
            {title: '详细地址', field: 'label_names'},
            {title: '开户银行账号', field: 'business_state'},
            {title: '是否三证全一', field: 'is_threeInOne'},
            {title: '营业执照电子版', field: 'business_licence_number_elc',align:'center',formatter: function(value,row,index){
                if(value){
                    return '<img src="'+RESOURCE_URL+value+'" width="50" height="50">'
                }
                return ''
            }},
            {title: '组织机构代码电子版', field: 'organization_code_electronic',align:'center',formatter: function(value,row,index){
                if(value){
                    return '<img src="'+RESOURCE_URL+value+'" width="50" height="50">'
                }
                return ''
            }},
            {title: '税务登记证号电子版', field: 'tax_registration_certif_elc',align:'center',formatter: function(value,row,index){
                if(value){
                    return '<img src="'+RESOURCE_URL+value+'" width="50" height="50">'
                }
                return ''
            }},
            {title: '三证合一证', field: 'three_licence_elc',align:'center',formatter: function(value,row,index){
                if(value){
                    return '<img src="'+RESOURCE_URL+value+'" width="50" height="50">'
                }
                return ''
            }},
            {title: '是否生效', field: 'is_active',formatter:function (value, row, index) {
                return value ===1 ?'生效':'无效'
            }}
        ]],
        onLoadSuccess: function (data) {
            if (data === null || data.total == 0) {
                var body = $(this).data().datagrid.dc.body2;
                body.find('table tbody').append('<tr><td width="' + body.width() + '" style="height: 35px; text-align: center;"><h1>暂无数据</h1></td></tr>');
            }
        }
    });
})

function openAdd() {
    location.href='/sys/customer/add';
}

function openEdit() {
    var rows = $('#listGrid').datagrid('getSelected');
    if (null == rows) {
        $.messager.alert("提示信息", "请选择需要编辑的行", "info");
        return;
    }
    location.href='/sys/customer/edit?id=' + rows.id;
}

function reload() {
    $('#listGrid').datagrid("reload");
}

